/*  Function LOVSampleReference
	author      : zeke
	log         : 18/02/2013    Creation
	desc        : LOV sample reference
					ao_option : - onSelect [function]
								- param [string]
*/
var LOVBuildSampleReference = function(ao_option){
	try{
		
		if(ao_option==undefined){ ao_option={}; }
		var lf_onSelect	= (ao_option.onSelect==undefined || typeof(ao_option.onSelect)!='function') ? function(){} : ao_option.onSelect;
		
		// Create Popup
		var $popup	= openPopup({ title:'Daftar Sample Reference' , width:700, height:370 });
		var ls_id	= $popup.attr('id');
		
		// Append Datagrid Container
		var ls_gridName	= 'grid_'+ls_id;
		$popup	.html(	$('<div>')	.attr('id', 'tb'+ls_id).attr('style','padding:5px;height:auto;')
									.html(	$('<div>').html($('<form>')	.attr('id','fm_search_'+ls_id).data('rel',ls_id).submit(function(e){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).data('rel')).serializeObject()); e.preventDefault(); })
																		.html('<table class="tb_form" style="margin-bottom:0px"><tr><td width="100">Keyword</td><td><input type="text" name="keyword" class="textfield medium" /><a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search'+ls_id+'" rel="'+ls_id+'">Search</a></td></tr></table>')
															)
											)
						)
				.append($('<div>').attr('id', ls_gridName).attr('toolbar', '#tb'+$popup.attr('id')));
		
		$('#btn_search'+ls_id).click(function(){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).attr('rel')).serializeObject()); return false; });
		$('#btn_search'+ls_id).linkbutton({  
			plain:true  
		}); 
		
		// Build Datagrid
		var ls_param = (ao_option.param==undefined ? '' : ao_option.param);
		$('#'+ls_gridName).datagrid({  
			url:gs_path+'/app_sample_reference/getdata/'+ls_param,
			queryParams: $('#fm_search_'+ls_id).serializeObject(),
			height:337,
			pagination:true,
			singleSelect:true,
			columns:[[
				{ field : 'ref_key', title : 'Key', width : 100, sortable:true },
				{ field : 'ref_name', title : 'Name', width : 300, sortable:true }
			]],
			onSelect:function(rowIndex, rowData){ lf_onSelect(rowData); closePopup(); }
		});
		
	} catch (err) { alert('Func. LOVSampleReference :\n' + err); }
};